package com.ms.module.wechat.clear.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;

import androidx.annotation.Nullable;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import com.ms.module.wechat.clear.R;
import com.ms.module.wechat.clear.base.BaseAppCompatActivity;
import com.ms.module.wechat.clear.base.StatusBarUtil;
import com.ms.module.wechat.clear.internal.ICloseListener;
import com.ms.module.wechat.clear.internal.WeChatClearCommonn;
import com.ms.module.wechat.clear.repository.SharedPreferencesData;
import com.ms.module.wechat.clear.repository.WeChatScanDataRepository;
import com.ms.module.wechat.clear.utils.ClearTempFileUtils;

public class ModuleWeChatClearActivity extends BaseAppCompatActivity implements ICloseListener {

    private NavController navController;

    @Override
    protected void setStatusBar() {
        StatusBarUtil.setColor(this, Color.parseColor("#4FACF2"), 0);
        StatusBarUtil.setDarkMode(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_module_wechat_clear;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WeChatClearCommonn.add(this::close);
        navController = Navigation.findNavController(this, R.id.fragment);
        navController.setGraph(R.navigation.com_ms_module_wechat_clear_navigation);
        navController.navigate(R.id.scanFragment);
    }

    @Override
    public void close() {
        finish();
        WeChatClearCommonn.getWeChatClearCallBack().onClose(this);
        WeChatScanDataRepository.getInstance().clear();
        ClearTempFileUtils.clear(this);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 更新扫描时间
        SharedPreferencesData.updateLastTimestamp();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 拦截返回键
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
